import 'package:flutter/material.dart';
import 'package:flutter_app/resources/pages/search_movie_page.dart';
import 'package:nylo_framework/nylo_framework.dart';

class SearchInput extends StatelessWidget {
  final FocusNode searchFocusNode;
  final String? query;
  final TextEditingController _controller;

  SearchInput({super.key, this.query, required this.searchFocusNode})
      : _controller = TextEditingController(text: query);

  @override
  Widget build(BuildContext context) {
    return TextField(
      cursorColor: Colors.black,
      controller: _controller,
      focusNode: searchFocusNode,
      decoration: InputDecoration(
        hintText: '搜索...',
        filled: true,
        fillColor: Colors.white,
        border: InputBorder.none,
        enabledBorder: OutlineInputBorder(
          borderSide: BorderSide.none,
          borderRadius: BorderRadius.circular(50),
        ),
        focusedBorder: OutlineInputBorder(
          borderSide: BorderSide.none,
          borderRadius: BorderRadius.circular(50),
        ),
        contentPadding: const EdgeInsets.symmetric(
          vertical: 0,
          horizontal: 20,
        ),
        suffixIcon: IconButton(
          icon: const Icon(Icons.search),
          onPressed: () {
            print('Search query: ${_controller.text}');
            if (_controller.text.isNotEmpty) {
              // 获取当前路由

              // 如果当前路由不是搜索页面，则跳转到搜索页面
              routeTo(
                SearchMoviePage.path,
                // navigationType: NavigationType.pushReplace,
                data: _controller.text,
              );
            }
          },
        ),
      ),
      style: const TextStyle(
        decoration: TextDecoration.none,
      ),
    );
  }
}
